#include "TrueText/Config.h"
#include "ShadowDrawer.h"
#include "BitmapLayer.h"
#include "BlittingFunction.h"
#include "TextDrawer.h"

namespace TrueText {

ShadowDrawer::ShadowDrawer(Drawer* sourceDrawer, const ShadowInfo& shadowInfo)
	: sourceDrawer(sourceDrawer)
	, shadowInfo(shadowInfo)
{ }

Rectangle ShadowDrawer::GetBounds(const TextLayout& layout)
{
	Rectangle textDrawerBounds = sourceDrawer->GetBounds(layout);
	textDrawerBounds.left += shadowInfo.GetOffset().x;
	textDrawerBounds.top += shadowInfo.GetOffset().y;
	textDrawerBounds.right += shadowInfo.GetOffset().x;
	textDrawerBounds.bottom += shadowInfo.GetOffset().y;

	return textDrawerBounds;
}

boost::shared_ptr<BitmapLayer> ShadowDrawer::Draw(const TextLayout& layout)
{
	boost::shared_ptr<BitmapLayer> result = sourceDrawer->Draw(layout);
	BlittingFunction fn = result->GetBlittingFunction();
	fn.SetColor(shadowInfo.GetColor());
	fn.SetBlendMode(BLEND_MAX);
	result->SetBlittingFunction(fn);
	result->SetOffset(shadowInfo.GetOffset());
	return result;
}

}